<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property string $id
 * @property string $idcard 身份证号
 * @property string $mobile_pre 手机号前缀
 * @property string $mobile 手机号
 * @property string $username 用户名
 * @property string $email 邮箱
 * @property string $nickname 昵称
 * @property string $avatar_url 头像链接(200*200)
 * @property string $created_at
 * @property string $updated_at
 * @property string $level 等级
 * @property string $integral 积分
 * @property string $funds 资金
 * @property string $frozen 冻结金额
 * @property string $token 认证令牌
 * @property string $key 认证钥匙
 * @property string $auth_key
 * @property string $password_hash 登陆密码
 * @property string $tp_pwd
 * @property string $random_string 随机字符串
 * @property int $status 状态
 * @property int $is_super 是否为超级用户
 *
 * @property Action[] $actions
 * @property Docu[] $docus
 * @property Docu[] $docus0
 * @property DocuBody[] $docuBodies
 * @property DocuBody[] $docuBodies0
 * @property DocuComment[] $docuComments
 * @property DocuComment[] $docuComments0
 * @property DocuCommentReply[] $docuCommentReplies
 * @property DocuCommentReply[] $docuCommentReplies0
 * @property DocuCommentReply[] $docuCommentReplies1
 * @property EquipmentAppVersion[] $equipmentAppVersions
 * @property EquipmentUser[] $equipmentUsers
 * @property Equipment[] $equipment
 * @property Menu[] $menus
 * @property Menu[] $menus0
 * @property QueneJob[] $queneJobs
 * @property Role[] $roles
 * @property RoleUser[] $roleUsers
 * @property Role[] $roles0
 * @property UserArea[] $userAreas
 * @property UserOperateLog[] $userOperateLogs
 * @property Yii2App[] $yii2Apps
 */
class User extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['created_at', 'updated_at', 'token', 'key', 'auth_key', 'password_hash', 'tp_pwd', 'random_string'], 'required'],
            [['created_at', 'updated_at', 'level', 'integral', 'status', 'is_super'], 'integer'],
            [['funds', 'frozen'], 'number'],
            [['tp_pwd'], 'string'],
            [['idcard'], 'string', 'max' => 20],
            [['mobile_pre'], 'string', 'max' => 5],
            [['mobile'], 'string', 'max' => 11],
            [['username', 'email'], 'string', 'max' => 191],
            [['nickname', 'avatar_url', 'password_hash'], 'string', 'max' => 255],
            [['token'], 'string', 'max' => 50],
            [['key', 'auth_key', 'random_string'], 'string', 'max' => 32],
            [['token'], 'unique'],
            [['username'], 'unique'],
            [['email'], 'unique'],
            [['idcard'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'idcard' => Yii::t('app', '身份证号'),
            'mobile_pre' => Yii::t('app', '手机号前缀'),
            'mobile' => Yii::t('app', '手机号'),
            'username' => Yii::t('app', '用户名'),
            'email' => Yii::t('app', '邮箱'),
            'nickname' => Yii::t('app', '昵称'),
            'avatar_url' => Yii::t('app', '头像链接(200*200)'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'level' => Yii::t('app', '等级'),
            'integral' => Yii::t('app', '积分'),
            'funds' => Yii::t('app', '资金'),
            'frozen' => Yii::t('app', '冻结金额'),
            'token' => Yii::t('app', '认证令牌'),
            'key' => Yii::t('app', '认证钥匙'),
            'auth_key' => Yii::t('app', 'Auth Key'),
            'password_hash' => Yii::t('app', '登陆密码'),
            'tp_pwd' => Yii::t('app', 'Tp Pwd'),
            'random_string' => Yii::t('app', '随机字符串'),
            'status' => Yii::t('app', '状态'),
            'is_super' => Yii::t('app', '是否为超级用户'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getActions()
    {
        return $this->hasMany(Action::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocus()
    {
        return $this->hasMany(Docu::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocus0()
    {
        return $this->hasMany(Docu::className(), ['updated_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuBodies()
    {
        return $this->hasMany(DocuBody::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuBodies0()
    {
        return $this->hasMany(DocuBody::className(), ['updated_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuComments()
    {
        return $this->hasMany(DocuComment::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuComments0()
    {
        return $this->hasMany(DocuComment::className(), ['updated_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuCommentReplies()
    {
        return $this->hasMany(DocuCommentReply::className(), ['at_user' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuCommentReplies0()
    {
        return $this->hasMany(DocuCommentReply::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuCommentReplies1()
    {
        return $this->hasMany(DocuCommentReply::className(), ['updated_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentAppVersions()
    {
        return $this->hasMany(EquipmentAppVersion::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentUsers()
    {
        return $this->hasMany(EquipmentUser::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipment()
    {
        return $this->hasMany(Equipment::className(), ['id' => 'equipment_id'])->viaTable('{{%equipment_user}}', ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMenus()
    {
        return $this->hasMany(Menu::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMenus0()
    {
        return $this->hasMany(Menu::className(), ['updated_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getQueneJobs()
    {
        return $this->hasMany(QueneJob::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoles()
    {
        return $this->hasMany(Role::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoleUsers()
    {
        return $this->hasMany(RoleUser::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoles0()
    {
        return $this->hasMany(Role::className(), ['id' => 'role_id'])->viaTable('{{%role_user}}', ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserAreas()
    {
        return $this->hasMany(UserArea::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserOperateLogs()
    {
        return $this->hasMany(UserOperateLog::className(), ['created_by' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getYii2Apps()
    {
        return $this->hasMany(Yii2App::className(), ['created_by' => 'id']);
    }
}
